package com.baichang.taoshunda.service.impl;

import com.baichang.framework.model.Page;
import com.baichang.taoshunda.dao.PaymentManagementDao;
import com.baichang.taoshunda.entity.PaymentManagement;
import com.baichang.taoshunda.service.PaymentManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/2/1 0001.
 */
@Service
public class PaymentManagementServiceImpl implements PaymentManagementService {

    @Autowired
    private PaymentManagementDao paymentManagementDao;

    /**
     * 查询时间金钱
     *
     * @param nowPage
     * @param pageSize
     * @return
     */
    @Override
    public Page queryTimeInfo(int nowPage, int pageSize) {
        return paymentManagementDao.queryTimeInfo(nowPage, pageSize);
    }

    /**
     * 添加
     *  @param months
     * @param monthsTwo
     * @param money
     * @param type      @return
     * @param remark
     * @param oldMoney
     */
    @Override
    public long addSelectTime(Integer months, Integer monthsTwo, BigDecimal money, Integer type, String remark, BigDecimal oldMoney) {
        PaymentManagement paymentManagement = new PaymentManagement();
        paymentManagement.setType(type);
        paymentManagement.setMoney(money);
        if (months == 0) {
            paymentManagement.setMonths(monthsTwo);
        }else {
            paymentManagement.setMonths(months);
        }
        paymentManagement.setOldMoney(oldMoney);
        paymentManagement.setRemark(remark);
        return paymentManagementDao.save(paymentManagement);
    }

    /**
     * 修改
     *
     * @param id
     * @param months
     * @param money
     * @param type
     * @param remark
     *@param oldMoney @return
     */
    @Override
    public int updateSelectTime(Integer id, Integer months, BigDecimal money, Integer type, String remark, BigDecimal oldMoney) {
        Map map = new HashMap();
        map.put("months", months);
        map.put("money", money);
        map.put("type", type);
        map.put("remark", remark);
        map.put("oldMoney", oldMoney);
        return paymentManagementDao.update(map, id);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Override
    public int delete(Integer id) {
        return paymentManagementDao.deleteById(id);
    }

    /**
     * 选择分类
     *
     * @param type
     * @return
     */
    @Override
    public List<Map<String, Object>> queryPaymentType(Integer type) {
        return paymentManagementDao.queryPaymentType(type);
    }
}
